$(document).ready(function() {
	var userId = $("#userId").val();
	
	var calendar = $('#calendar').fullCalendar({
		aspectRatio: 0.75, //单元格宽与高度的比值
		header : {
			left : 'prev,next today',
			center : 'title',
			right : 'month'
		},
		selectable : true,
		selectHelper : true,
		select : function(start, end, allDay) {
			//跳到当天的任务列表页面
			window.location.href='wx/task/task_daily/'+userId+"?keyword="+start.format("yyyy-MM-dd");
		},
		eventClick: function(calEvent, jsEvent, view) { 

		},
		editable : true,
		events: function(start, end, callback) {
			var url = 'wx/task/load/1/'+userId;
			
	        $.ajax({
	            url: url,
	            type: "get",
	            data: {
	                start: start.format("yyyy-MM-dd"),
	                end: end.format("yyyy-MM-dd")
	            },
	            success: function(data) {
	            	data = eval(data);
	                var events = [];
	                for(var i=0; i < data.length; i++){
	                	 var startDate = data[i].start;
	                	 var endDate = data[i].end;
	                	
	                	 if(startDate == '' || endDate == ''){
	                		 var startDate = new Date();
		                	 var endDate = new Date();
	                	 }
	               
	                	 events.push({
		                       title: data[i].content,
		                       start: startDate,
		                       end: endDate
		                 });
	                }
	                
	                callback(events);
	            }
	        });
	    },
		loading: function(bool) {
			if (bool) $('#loading').show();
			else $('#loading').hide();
		}
	});

});